﻿using StackExchange.Redis;

public class RedisService
{
    private readonly ConnectionMultiplexer _redisConnection;
    private readonly IDatabase _database;

    public RedisService(IConfiguration configuration)
    {
        var redisConnectionString = configuration.GetConnectionString("Redis");
        _redisConnection = ConnectionMultiplexer.Connect(redisConnectionString);
        _database = _redisConnection.GetDatabase();
    }

    public void SetValue(string key, string value)
    {
        //_database.StringSet(key, value);
        _database.StringSet(key, value, TimeSpan.FromSeconds(100));
    }

    public string GetValue(string key)
    {
        return _database.StringGet(key);
    }

    public bool DelValue(string key)
    {
        return _database.KeyDelete(key);
    }

    public bool isExists(string key)
    {
        return _database.KeyExists(key);
    }
}